
// 导入redux中actions标识
import types from '../types'

// 定义初始购物车仓库
const defaultState = {
    prolist: [
        {
            id: 1,
            name: '迪奥',
            price: 399
        },
        {
            id: 2,
            name: '连衣裙',
            price: 499
        }
    ],
    pronum: 1000,
    schoollist: [], // 学校列表数据
}

// 定义购物车reducer函数
function shopReducer(state = defaultState, action) {
    // 添加商品
    if (action.type == types.a) {
        //  console.log('action', action);
        state.prolist.push(action.payload)
        // console.log('state', state);
        return {
            ...state,
            prolist: state.prolist
        }
    }
    // pronum增加
    if (action.type == types.b) {
        return {
            ...state,
            pronum: state.pronum + action.payload
        }
    }
    // 初始化学校列表
    if (action.type == types.e) {
        return {
            ...state,
            schoollist: action.payload
        }
    }

    // 如果不修改返回原state
    return state
}

// 导出shopReducer
export default shopReducer